package com.hisense.ovcloud.mqtt.monitor.routers;

import com.hisense.ovcloud.commons.configs.validator.BaseRouterConfiguration;
import com.hisense.ovcloud.mqtt.monitor.service.MQTTClientConnector;
import lombok.SneakyThrows;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.path;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

@Configuration
public class RoutingConfiguration extends BaseRouterConfiguration {

    private final MQTTClientConnector mqttClientConnector;

    public RoutingConfiguration(MQTTClientConnector mqttClientConnector) {
        this.mqttClientConnector = mqttClientConnector;
    }

    @SneakyThrows
    @Bean
    public RouterFunction<ServerResponse> authRoutes() {
        return RouterFunctions.nest(path("/"),
                route()
                    .POST("/monitor", mqttClientConnector::monitor)
                    .build());
    }
}

